﻿using System;
using System.Collections.Concurrent;
using System.Net.WebSockets;

namespace WebSocketApi.Interface;


/// <summary>
/// Socket对象管理
/// </summary>
public interface ISocketDataManager
{

    /// <summary>
    /// 获取所有连接
    /// </summary>
    /// <returns></returns>
    ConcurrentDictionary<string, WebSocket> GetAllConnections();

    /// <summary>
    /// 根据Id获取指定Socket连接
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    WebSocket GetSocketById(string id);

    /// <summary>
    /// 获取Socket连接ID
    /// </summary>
    /// <param name="socket"></param>
    /// <returns></returns>
    string GetSocketId(WebSocket socket);
        
    /// <summary>
    /// 连接账号获取SocketId
    /// </summary>
    /// <param name="account"></param>
    /// <returns></returns>
    string GetSocketId(string account);

    /// <summary>
    /// 总连接数
    /// </summary>
    /// <returns></returns>
    int GetCount();

    /// <summary>
    /// 删除指定ID的Socket，并关闭该连接
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    Task RemoveSocketAsync(string id);

    /// <summary>
    /// 添加新的Socket
    /// </summary>
    /// <param name="socketId"></param>
    /// <param name="socket"></param>
    Task<bool> AddSocket(string socketId, WebSocket socket);

    /// <summary>
    /// 变更Socket令牌
    /// </summary>
    /// <param name="oldSocketKey"></param>
    /// <param name="newSocketKey"></param>
    /// <returns></returns>
    Task<bool> EditSocketKey(string oldSocketKey, string newSocketKey);
}
